<%@page import="java.util.UUID"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp" %>
<%
    String uuid = UUID.randomUUID().toString();
    request.setAttribute("uuid", uuid);
%>
<jsp:include page="/WEB-INF/pages/platform/optAuth/includeOptAuthGrid.jsp"/>
<jsp:include page="/WEB-INF/pages/platform/optBtn/includeOptBtnGrid.jsp"/>

<div class="row">
    <div class="col-md-6"  >
    	<div class="box box-primary">
    		<div class="box-header with-border">
    			<h3 class="box-title">
    			
    			</h3>
    			<div class="box-tools pull-right" id="funcPointGridTB_${uuid}">
    				<shiro:hasPermission name="FUNCPOINT_ADD">
			    		<button class="btn btn-sm btn-success addBtn">
			    			<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加
			    		</button>
		    		</shiro:hasPermission>
		    		<shiro:hasPermission name="FUNCPOINT_MOD">
			    		<button class="btn btn-sm btn-primary editBtn">
			    			<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 修改
			    		</button>
		    		</shiro:hasPermission>
		    		<shiro:hasPermission name="FUNCPOINT_DEL">
		    		<button class="btn btn-sm btn-danger delBtn">
		    			<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除
		    		</button>
		    		</shiro:hasPermission>
		    		
		    		<shiro:hasPermission name="FUNCPOINT_MOD">
			    		<div class="btn-group">
						  <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
						   	 交换 <span class="caret"></span>
						  </button>
						  <ul class="dropdown-menu">
						    <li><a href="javascript:void(0)" class="expBtn">导出</a></li>
						    <li><a href="javascript:void(0)" class="impBtn" id="impFuncPointBtn">导入</a></li>
						  </ul>
						</div>
					</shiro:hasPermission>
					
    			</div>
    		</div>
    		<div class="box-body">
            	 <table id="funcPointGrid_${uuid}">
            	 
            	 </table>
            </div><!-- /.box-body -->
    	</div>
    </div>
    <div id="tab_${uuid}" class="col-md-6 ">
    	<div class="nav-tabs-custom">
    		<ul class="nav nav-tabs" role="tablist">
	    		<li class="active">
	    			<a href="#optAuthTab_${uuid }" role="tab" data-toggle="tab">
	    			<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> 操作权限
	    			</a>
	    		</li>
	    		<li>
	    			<a href="#optBtnTab_${uuid }" role="tab" data-toggle="tab">
	    			<span class="glyphicon glyphicon-paperclip" aria-hidden="true"></span> 按钮设置
	    			</a>
	    		</li>
	    	</ul>
	    	<div class="tab-content">
	    		<div role="tabpanel" class="tab-pane active" id="optAuthTab_${uuid}">
	    	 		<div class="box-header with-border" id="optAuthGridTB_${uuid}">
	    	 			<shiro:hasPermission name="OPTAUTH_ADD">
	    	 			<button class="btn btn-sm btn-success batAddBt">
			    			<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span> 批量添加
			    		</button>
			    		</shiro:hasPermission>
			    		
			    		<shiro:hasPermission name="OPTAUTH_ADD">
			    		<button class="btn btn-sm btn-success addBt">
			    			<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加
			    		</button>
			    		</shiro:hasPermission>
			    		
			    		<shiro:hasPermission name="OPTAUTH_MOD">
			    		<button class="btn btn-sm btn-primary editBt">
			    			<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 修改
			    		</button>
			    		</shiro:hasPermission>
			    		
			    		<shiro:hasPermission name="OPTAUTH_AUTH">
			    		<button class="btn btn-sm btn-info roleAuthBt">
			    			<span class="glyphicon glyphicon-check" aria-hidden="true"></span> 授权
			    		</button>
			    		</shiro:hasPermission>
			    		
			    		<shiro:hasPermission name="OPTAUTH_DEL">
			    		<button class="btn btn-sm btn-danger delBt">
			    			<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除
			    		</button>
			    		</shiro:hasPermission>
			    	</div>
			    	<div class="box-body">
						<table id="optAuthGrid_${uuid}" style="width: 100%"></table>
					</div><!-- /.box-body -->
	    	 	</div>
	    	 	<div role="tabpanel" class="tab-pane" id="optBtnTab_${uuid}">
	    	 		<div class="box-header with-border" id="optBtnGridTB_${uuid}">
			    		<shiro:hasPermission name="OPTBTN_ADD">
			    		<button class="btn btn-sm btn-success batAddBt">
			    			<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span> 批量添加
			    		</button>
			    		</shiro:hasPermission>
			    		
			    		<shiro:hasPermission name="OPTBTN_ADD">
			    		<button class="btn btn-sm btn-success addBt">
			    			<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加
			    		</button>
			    		</shiro:hasPermission>
			    		
			    		<shiro:hasPermission name="OPTBTN_MOD">
			    		<button class="btn btn-sm btn-primary editBt">
			    			<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 修改
			    		</button>
			    		</shiro:hasPermission>
			    		
			    		<shiro:hasPermission name="OPTBTN_AUTH">
			    		<button class="btn btn-sm btn-info roleAuthBt">
			    			<span class="glyphicon glyphicon-check" aria-hidden="true"></span> 授权
			    		</button>
			    		</shiro:hasPermission>
			    		
			    		<shiro:hasPermission name="OPTBTN_DEL">
			    		<button class="btn btn-sm btn-danger delBt">
			    			<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 删除
			    		</button>
			    		</shiro:hasPermission>
			    		
			    	</div>
			    	<div class="box-body">
						<table id="optBtnGrid_${uuid}"  style="width: 100%"></table>
					</div><!-- /.box-body -->
	    	 	</div>
	    	</div>
    	</div>
    </div>
</div>
<script type="text/javascript">

    $(function () {
        var uuid = '${uuid}';
        
        var _funcPointGridTB=$("#funcPointGridTB_"+uuid);
        
        var funcPointGrid = $("#funcPointGrid_"+uuid).bootstrapTable({
        	url:ctx + "/funcPointAction/queryFuncPoints.do",
        	filterControl:true,
        	columns:[
				{field: '_id',checkbox:true},
                {title: '功能点名称', field: 'name', width: "210px",filterControl:"input"},
                {title: 'URL地址', field: 'url',filterControl:"input"}
        	],
        	onClickRow:function(row){
        		var id=row.id;
        		optAuthGrid.funcPointId = id;
                optAuthGrid.bootstrapTable("refresh");
                
                optBtnGrid.funcPointId = id;
                optBtnGrid.bootstrapTable("refresh");
        	}
        });
        
        _funcPointGridTB.find(".addBtn").click(function(){
        	var sub = top.webUtils.topicSubscribe("funcPoint.edit.success", function (args) {
                dialog.close();
                funcPointGrid.bootstrapTable("refresh");
            });
            var dialog = editFuncPoint({
                onClose: function () {
                    sub.remove();
                }
            });
        });
        
        _funcPointGridTB.find(".editBtn").click(function(){
        	var rows=funcPointGrid.bootstrapTable("getSelections");
        	if(rows && rows.length>0){
        		var sub = top.webUtils.topicSubscribe("funcPoint.edit.success", function (args) {
            		dialog.close();
            		funcPointGrid.bootstrapTable("refresh");
                });
        		var row=rows[0];
        		var dialog= editFuncPoint({
                	id:row.id,
                    onClose: function () {
                        sub.remove();
                    }
                });
        	} else {
        		webUtils.alert("请选择需要编辑的数据");
            }
            
        });
        
        _funcPointGridTB.find(".delBtn").click(function(){
        	var rows=funcPointGrid.bootstrapTable("getSelections");
        	if(rows && rows.length>0){
        		webUtils.confirm("删除后将不可恢复，请问是否继续?", function(result) {
					if(result){
						var selecteds = [];
		                $.each(rows, function (i, n) {
		                    selecteds.push(n.id);
		                });
		                $.post(ctx + "/funcPointAction/delFuncPoint.do", {
		                    ids: selecteds.join(",")
		                }, function (data) {
		                    if (data.success) {
		                    	funcPointGrid.bootstrapTable("refresh");
		                    } else {
		                    	webUtils.alert(data.msg);
		                    }
		                }, 'json');
					}
        		});
        		
        	} else {
        		webUtils.alert("请选择需要删除的数据");
            }
            
        });
        
        _funcPointGridTB.find(".expBtn").click(function(){
        	var rows=funcPointGrid.bootstrapTable("getSelections");
        	if(rows && rows.length>0){
        		var ids = [];
                $.each(rows, function (i, n) {
                	ids.push(n.id);
                });
        		window.open(ctx + "/funcPointAction/export.do?ids="+ids.join(","));
        	} else {
        		webUtils.alert("请选择需要导出的数据");
            }
        });
        
        var uploader
        webUtils.fileUploader({
        	server:ctx+"/funcPointAction/import.do",
        	uploadPick:"#impFuncPointBtn",
        	duplicate:false,
        	accept: {
                title: 'json文件类型',
                //需要与platform.upload.allowFileTypes配置保持一致
                extensions: 'json'
            },
            afterInit:function(u,uder){
            	uploader=u;
            }
        });
        
        _funcPointGridTB.find(".impBtn").mouseenter(function(){
        	uploader.refresh();
        });
        
        var optAuthGrid = new wiseMen.platform.optAuthGrid({
        	gridDom:$("#optAuthGrid_"+uuid),
        	toolbarSelector:"#optAuthGridTB_"+uuid
        });
        
        var optBtnGrid=new wiseMen.platform.optBtnGrid({
        	gridDom:$("#optBtnGrid_"+uuid),
        	toolbarSelector:"#optBtnGridTB_"+uuid
        });
        
        var editFuncPoint = function (params) {
            params = params || {};
            var t = [];
            if (params.id) {
                t.push("id=" + params.id);
            }
            
            var dialog=webUtils.dialog({
           	 title:'编辑功能点',
           	 url:ctx + '/funcPointAction/editView.do?' + t.join("&"),
           	 onremove:function () {
                    if (params.onClose) {
                        params.onClose.call(null);
                    }
                }
            });
            return dialog;
        };
    });
</script>

